{template 'common/header-storex'}

{if $op == 'display'}
<div class="wn-main">
	<div class="wn-main__head">应用</div>
	<div class="wn-main__content">
		<div class="wn-tabs">
			<div class="wn-tabs__item wn-tabs__item--active">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_article', array('storeid' => $_GPC['storeid'], 'op' => 'display'))}">文章管理</a>
			</div>
			<div class="wn-tabs__item">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_article', array('storeid' => $_GPC['storeid'], 'op' => 'category'))}">文章分类</a>
			</div>
		</div>
		<div class="pull-right">
			<a href="{php echo $this->createWebUrl('shop_article', array('op' => 'post', 'storeid' => $_GPC['storeid']))}" class="btn btn-primary">+添加文章</a>				
		</div>
		<div class="clearfix">
			<table class="table table-hover wn-table table-bordered">
				<thead class="navbar-inner">
					<tr>
						<th>文章标题</th>
						<th>创建时间</th>
						<th>阅读量</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					{loop $article_list $article}
					<tr>
						<td>
							<span class="label label-primary">{$article['category_title']}</span>&nbsp;
							{$article['title']}
						</td>
						<td>{php echo date('Y-m-d H:i:s', $article['createtime'])}</td>
						<td>{$article['click']}</td>
						<td>
							{if $article['status'] == 1}
							<a class="wn-table__link__item" href="{php echo $this->createWebUrl('shop_article', array('op' => 'status', 'storeid' => $_GPC['storeid'], 'id' => $article['id'], 'status' => 2))}">开启中</a>
							{elseif $article['status'] == 2}
							<a class="wn-table__link__item" href="{php echo $this->createWebUrl('shop_article', array('op' => 'status', 'storeid' => $_GPC['storeid'], 'id' => $article['id'], 'status' => 1))}">已关闭</a>
							{/if}
						</td>
						<td>
							<a href="{php echo $this->createWebUrl('shop_article', array('op' => 'post', 'id' => $article['id'], 'storeid' => $_GPC['storeid']))}" class="wn-table__link__item">编辑</a>
							<a onclick="return confirm('确定删除吗?')" href="{php echo $this->createWebUrl('shop_article', array('op' => 'delete', 'id' => $article['id'], 'storeid' => $_GPC['storeid']))}" class="wn-table__link__item">删除</a>
						</td>
					</tr>
					{/loop}
				</tbody>
			</table>
		</div>
	</div>
</div>
{/if}

{if $op == 'post'}
<div class="wn-main">
	<div class="wn-main__head">应用</div>
	<div class="wn-main__content">
		<div class="wn-tabs">
			<div class="wn-tabs__item wn-tabs__item--active">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_article', array('storeid' => $_GPC['storeid'], 'op' => 'display'))}">文章管理</a>
			</div>
			<div class="wn-tabs__item">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_article', array('storeid' => $_GPC['storeid'], 'op' => 'category'))}">文章分类</a>
			</div>
		</div>
		<div class="clearfix">
			<form action="" method="post" class="article-post" enctype="multipart/form-data">
				<div class="we7-form" id="js-wesite-article-post">
					<div class="form-group">
						<label for="" class="control-label col-sm-2">排序</label>
						<div class="form-controls col-sm-8">
							<input type="text" class="form-control" name="displayorder" value="{$article_info['displayorder']}">
							<span class="help-block">文章的显示顺序，越大则越靠前 </span>
						</div>
					</div>
					<div class="form-group">
						<label for="" class="control-label col-sm-2">标题</label>
						<div class="form-controls col-sm-8">
							<input type="text" class="form-control" name="title" value="{$article_info['title']}">
							<span class="help-block">文章标题 </span>
						</div>
					</div>
					<div class="form-group" style="display:none;">
						<label for="" class="control-label col-sm-2">文章来源</label>
						<div class="form-controls col-sm-8">
							<input type="text" class="form-control" name="source">
							<span class="help-block">文章来源 </span>
						</div>
					</div>
					<div class="form-group">
						<label for="" class="control-label col-sm-2">文章作者</label>
						<div class="form-controls col-sm-8">
							<input type="text" class="form-control" name="author" value="{$article_info['author']}">
							<span class="help-block">文章作者 </span>
						</div>
					</div>
					<div class="form-group">
						<label for="" class="control-label col-sm-2">缩略图</label>
						<div class="col-sm-8 form-controls">
								{php echo tpl_form_field_image('thumb', $article_info['thumb'])}
							<div class="help-block">封面（大图片建议尺寸：360像素 * 200像素）</div>
						</div>
					</div>
					<div class="form-group form-inline">
						<label class="control-label col-sm-2">文章类别</label>
						<div class="form-controls col-sm-8">
							<select name="pcate" class="col-sm-12">
								{loop $category_list $category}
								<option value="{$category['id']}" {if $category['id'] == $article_info['pcate']}selected{/if}>{$category['title']}</option>
								{/loop}
							</select>
						</div>
					</div>
					<div class="form-group">
						<label for="" class="control-label col-sm-2">简介</label>
						<div class="form-controls col-sm-8">
							<textarea class="form-control" name="description" rows="5">{$article_info['description']}</textarea>
						</div>
					</div>
					<div class="form-group">
						<label for="" class="control-label col-sm-2">内容</label>
						<div class="form-controls col-sm-8">
							{php echo tpl_ueditor('content', $article_info['content']);} 
						</div>
					</div>
					<div class="form-group">
						<label for="" class="control-label col-sm-2">阅读次数</label>
						<div class="form-controls col-sm-8">
							<input class="form-control" type="text" name="click" value="{$article_info['click']}">
							<span class="help-block">默认为0。您可以设置一个初始值,阅读次数会在该初始值上增加。</span>
						</div>
					</div>
					<div class="form-group" style="display:none;">
						<label for="" class="control-label col-sm-2">是否赠送积分</label>
						<div class="form-controls col-sm-8">
							<input type="radio" name="credit[status]" value="1" id="credit1">
							<label for="credit1">赠送</label>
							<input type="radio" name="credit[status]" value="0" id="credit0">
							<label for="credit0">不赠送</label>
							<span class="help-block">设置赠送积分后,粉丝在分享时赠送积分.粉丝的好友在点击阅读时,也会赠送积分</span>
						</div>
					</div>
					<div class="form-group" style="display:none;">
						<label for="" class="control-label col-sm-2">赠送积分上限</label>
						<div class="form-controls col-sm-8">
							<input type="text" class="form-control" name="credit[limit]">
							<span class="help-block">设置赠送积分的上限,到达上限后将不再赠送积分</span>
							<span class="help-block" ng-if="id">已经赠送了<strong class="text-danger"> {php echo $credit_num ? $credit_num : 0} </strong>积分,还可以赠送<strong class="text-danger"> {php echo $credit_yu ? $credit_yu : 0} </strong>积分</span>
						</div>
					</div>
					<div class="form-group" style="display:none;">
						<label for="" class="control-label col-sm-2">转发赠送积分</label>
						<div class="form-controls col-sm-8">
							<input type="text" class="form-control"  name="credit[share]">
							<span class="help-block">设置转发时赠送积分</span>
						</div>
					</div>
					<div class="form-group" style="display:none;">
						<label for="" class="control-label col-sm-2">阅读赠送积分</label>
						<div class="form-controls col-sm-8">
							<input type="text" class="form-control" name="credit[click]">
							<span class="help-block">设置阅读时赠送给分享人的积分</span>
						</div>
					</div>
					<input name="submit" value="发布" class="btn btn-primary btn-submit" type="submit">
					<input type="hidden" name="token" value="{$_W['token']}" />
					<input type="hidden" name="id" value="{$id}">
				</div>
			</form>
		</div>
	</div>
</div>
{/if}

{if $op == 'category'}
<div class="wn-main">
	<div class="wn-main__head">应用</div>
	<div class="wn-main__content">
		<div class="wn-tabs">
			<div class="wn-tabs__item">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_article', array('storeid' => $_GPC['storeid'], 'op' => 'display'))}">文章管理</a>
			</div>
			<div class="wn-tabs__item wn-tabs__item--active">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_article', array('storeid' => $_GPC['storeid'], 'op' => 'category'))}">文章分类</a>
			</div>
		</div>
		<div class="clearfix">
			<table class="table table-hover wn-table table-bordered">
				<thead class="navbar-inner">
					<tr>
						<th>分类名称</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					{loop $category_list $category}
					<tr>
						<td>{$category['title']}</td>
						<td>
							{if $category['status'] == 1}
							<a class="wn-table__link__item" href="{php echo $this->createWebUrl('shop_article', array('op' => 'category_status', 'storeid' => $_GPC['storeid'], 'id' => $category['id'], 'status' => 2))}">开启中</a>
							{elseif $category['status'] == 2}
							<a class="wn-table__link__item" href="{php echo $this->createWebUrl('shop_article', array('op' => 'category_status', 'storeid' => $_GPC['storeid'], 'id' => $category['id'], 'status' => 1))}">已关闭</a>
							{/if}
						</td>
						<td>
							<a href="javascript:;" class="wn-table__link__item js-edit-category" data-id="{$category['id']}">编辑</a>
							<a href="{php echo $this->createWebUrl('shop_article', array('op' => 'category_delete', 'id' => $category['id'], 'storeid' => $_GPC['storeid']))}" class="wn-table__link__item">删除</a>
						</td>
					</tr>
					{/loop}
					<tr>
						<td colspan=3>
							<a href="javascript:;" class="js-add-category">添加分类</a>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="modal fade" id="category-modal" tabindex="-1" role="dialog" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="myModalLabel">添加分类</h4>
						</div>
						<div class="modal-body clearfix form-horizontal">
							<div class="form-group">
								<div class="col-sm-12 col-xs-12">
									<div class="input-group">
										<span class="input-group-addon">分类名称</span>
										<input type="text" name="title" value="" class="form-control">
									</div>
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<input type="hidden" name="category_id">
							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							<button type="button" class="btn btn-primary js-submit-category">确定</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$('.js-add-category').click(function() {
		$('#category-modal').modal('show');
	});
	$('.js-edit-category').click(function() {
		id = $(this).data('id');
		$('input[name="category_id"]').val(id);
		$.post("{php echo $this->createWebUrl('shop_article', array('storeid' => $_GPC['storeid'], 'op' => 'category_info'))}", {id : id}, function(data) {
			data = $.parseJSON(data);
			if (data.message.errno != 0) {
				util.message(data.message.message, '', 'error');
			} else {
				$('input[name="title"]').val(data.message.message.title);
				$('#category-modal').modal('show');
			}
		});
	});
	$('.js-submit-category').click(function() {
		title = $('input[name="title"]').val();
		id = $('input[name="category_id"]').val();
		if (title) {
			$.post("{php echo $this->createWebUrl('shop_article', array('storeid' => $_GPC['storeid'], 'op' => 'category'))}", {id : id, title : title}, function(data) {
				data = $.parseJSON(data);
				if (data.message.errno != 0) {
					util.message(data.message.message, '', 'error');
				} else {
					util.message('编辑成功', location.href, 'success');
					$('#category-modal').modal('hide');
				}
			});
		} else {
			util.message('请填写名称', '', 'error');
		}
	});
</script>
{/if}
{template 'common/footer-storex'}